package com.example.demo1.action;

import com.example.demo1.model.User;
import com.example.demo1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserAction {
    @Autowired
    UserService userService;

    //陈泽源10.17
    @RequestMapping("/login")
    public String login(User user, HttpSession session, Model model){
        System.out.println("userlogin:"+user);
        User dbUser=userService.existsUser(user);
        //System.out.println(user.getUserName()+","+user.getPassword()+"--------"+user1);
        if(dbUser!=null){
            session.setAttribute("USER_SESSION", dbUser);
            model.addAttribute("active", 0);
            return "/home";
        }
        model.addAttribute("msg", "账号或密码错误，请重新输入！");
        return "/login";
    }
    @RequestMapping("/home")
    public String home(Model model){
        model.addAttribute("active", 0);
        return "/home";
    }
}
